package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/vehicle")
public class VehicleController {
    @Autowired
    VehicleService vehicleService;

    @GetMapping("/select")
    public JsonResult select(VehicleQuery vehicleQuery) {
        log.debug("查询车辆信息-入参:{}", vehicleQuery);
        log.debug("查询车辆信息-vehicleService:入参:{}", vehicleQuery);
        List<VehicleVO> vehicleVOList = vehicleService.selectVehicle(vehicleQuery);
        log.debug("查询车辆信息-vehicleService:入参:{},出参:{}", vehicleQuery,vehicleVOList);
        JsonResult result = JsonResult.ok(vehicleVOList);
        log.debug("查询车辆信息-入参:{},出参:{}", vehicleQuery, vehicleVOList);
        return result;
    }

    @PostMapping("/save")
    public JsonResult save(VehicleSaveParam vehicleSaveParam) {
        log.debug("保存车辆信息-入参:{}", vehicleSaveParam);
        log.debug("保存车辆信息-vehicleService:入参:{}", vehicleSaveParam);
        vehicleService.saveVehicle(vehicleSaveParam);
        log.debug("保存车辆信息-vehicleService:入参:{},出参:{}", vehicleSaveParam);
        JsonResult result = JsonResult.ok();
        log.debug("保存车辆信息-入参:{},出参:{}", vehicleSaveParam, result);
        return result;
    }

    @PostMapping("/delete/{vehicleId}")
    public JsonResult delete(@PathVariable Long vehicleId) {
        log.debug("删除用户信息-入参:{}", vehicleId);
        log.debug("删除用户信息-vehicleService:入参:{}", vehicleId);
        Boolean flag =vehicleService.deleteVehicle(vehicleId);
        log.debug("删除用户信息-vehicleService:入参:{},出参:{}", vehicleId, flag);
        JsonResult result = JsonResult.ok();
        log.debug("删除用户信息-入参:{},出参:{}", vehicleId, result);
        return result;
    }

    @PostMapping("/unbind/{vehicleId}")
    public JsonResult unbind(@PathVariable Long vehicleId) {
        log.debug("解绑用户信息-入参:{}", vehicleId);
        log.debug("解绑用户信息-vehicleService:入参:{}", vehicleId);
        vehicleService.unbind(vehicleId);
        log.debug("解绑用户信息-vehicleService:入参:{},出参:{}", vehicleId);
        JsonResult result = JsonResult.ok();
        log.debug("解绑用户信息-入参:{},出参:{}", vehicleId, result);
        return result;
    }

    @PostMapping("/bind/{geofenceId}/{id}")
    public JsonResult bind(@PathVariable Long geofenceId,@PathVariable Long id) {
        log.debug("绑定用户信息-入参:{},{}", geofenceId, id);
        log.debug("绑定用户信息-vehicleService:入参:{},{}", geofenceId, id);
        vehicleService.bind(geofenceId, id);
        log.debug("绑定用户信息-vehicleService:入参:{},{},出参:{}", geofenceId, id);
        JsonResult result = JsonResult.ok();
        log.debug("绑定用户信息-入参:{},{},出参:{}", geofenceId, id, result);
        return result;
    }

}
